<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('登录日志')"/>
</head>
<body>
<div class="layui-layout layui-layout-iframe">
    <div class="layui-fluid">
        <div class="layui-card">
            <!--search form-->
            <form class="layui-form layui-card-header layuiadmin-card-header-auto search-form" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">登录地址</label>
                        <div class="layui-input-inline">
                            <input class="layui-input" type="text" name="ipaddr" placeholder="" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">登录名称</label>
                        <div class="layui-input-inline">
                            <input class="layui-input" type="text" name="loginName" placeholder="" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">登录状态</label>
                        <div class="layui-input-inline input-sm">
                            <select name="status" th:with="type=${@dict.getType('sys_common_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline mt5">
                        <label class="layui-form-label">登录时间</label>
                        <div class="layui-input-inline input-sm">
                            <input class="layui-input" type="text" name="params[beginTime]" id="startTime" placeholder="开始时间" />
                        </div>
                        <span class="layui-form-mid">-</span>
                        <div class="layui-input-inline input-sm">
                            <input class="layui-input" type="text" name="params[endTime]" id="endTime" placeholder="结束时间"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button  type="button" class="layui-btn layuiadmin-btn-list" data-type="reload" lay-submit lay-filter="form-search" id="form-search"><i class="layui-icon">&#xe615;</i>搜索</button>
                    </div>
                </div>
            </form>
            <!--table actcion-->
            <div class="layui-card-body">
                <script type="text/html" id="table_operlog_toolbar">
                    <div class="layui-btn-group">
                        <button class="layui-btn layui-btn-sm" lay-event="toolbar-dict-remove"><i class="layui-icon">&#xe640;</i>删除</button>
                    </div>
                </script>
                <table id="table_logininfor" lay-filter="table_logininfor"></table>
                <script type="text/html" id="col_operation">
                    <a  href="javascript:;" lay-event="del">删除</a>
                </script>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:logininfor:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:logininfor:remove')}]];
    var prefix = ctx + "monitor/logininfor";
</script>
<script>
    layui.use(['common'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            form = layui.form,
            common = layui.common,
            laydate = layui.laydate,
            table = layui.table;
        //页面事件列表
        var active = {
            reload: function () {
                search(false);
            },
            remove: function (ids) {
                common.ajaxRemove(prefix + "/remove", ids, function (res) {
                    active['reload'].call(this);
                });
            }
        };
        //开始日期
        var insStart = laydate.render({
            elem: '#startTime'
            , min: 0
            , done: function (value, date) {
                //更新结束日期的最小日期
                insEnd.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                insEnd.config.elem[0].focus();
            }
        });
        //结束日期
        var insEnd = laydate.render({
            elem: '#endTime'
            , min: 0
            , done: function (value, date) {
                //更新开始日期的最大日期
                insStart.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        //查询表单
        form.on('submit(form-search)', function (data) {
            search(true);
        });
        //表格
        table.render({
            elem: '#table_logininfor'
            , method: 'post'
            , url: prefix + "/list" //数据接口
            , toolbar: '#table_logininfor_toolbar'
            , defaultToolbar: []
            , autoSort: false 	//关闭前端排序 使用后端排序
            , limit: getPageSize()
            , limits: getPageList()
            , text: getLoadErrorMsg()
            , page: true
            , cols: new Array([
                {field: 'loginName', title: '登录名称'}
                , {field: 'ipaddr', title: '登录地址',width:100}
                , {field: 'loginLocation', title: '登录地点'}
                , {field: 'browser', title: '浏览器'}
                , {field: 'os', title: '操作系统',width: 100}
                , {
                    field: 'status', title: '状态', width: 80, align: 'center',
                    templet: function (item) {
                        if (item.status === "0") {
                            return "<span class=\"layui-btn layui-btn-xs layui-btn-radius\">成功</span>";
                        } else {
                            return "<span class=\"layui-btn layui-btn-xs layui-btn-danger layui-btn-radius\">失败</span>";
                        }
                    }
                }
                , {field: 'msg', title: '提示消息'}
                , {field: 'loginTime', title: '访问时间', sort: true, width: 160}
            ])
        });
        //表格工具栏按钮事件
        table.on('toolbar(table_logininfor)', function (obj) {
            switch (obj.event) {
                case 'toolbar-logininfor-remove':
                    var checks = table.checkStatus('table_logininfor');
                    var ids = common.joinArray(checks.data, "infoId");
                    active['remove'].call(this, ids);
                    break;
            }
        });
        //表格事件
        table.on('tool(table_logininfor)', function (obj) {
            switch (obj.event) {
                case 'del':
                    active['remove'].call(this, obj.data.infoId);
                    break;
            }
        });
    });

    //表格查询
    function search(isResetCurr) {
        var field = serializeJson($('#searchForm'));
        var sortParam = getSort('table_logininfor');
        if (sortParam) {
            field.orderByColumn = sortParam.sortField;
            field.isAsc = sortParam.sortMethod;
        }
        //执行重载
        var options = {where: field};
        if (isResetCurr == true) {
            options.page = {curr: 1};
        }
        layui.table.reload('table_logininfor', options);
    }
</script>
</body>
</html>